define(function(require, exports){
	var pubjs  = require('pubjs');
	var util   = require('util');
	var view   = require('@base/view');
	var $      = require('jquery');
	var popwin = require('@base/dialog').base;
	var dspUtil = require('dspUtil');

	// 出价方式候选项配置
	var CHARGE_TYPE_OPTS = [
		{value: 0, label: LANG("竞价CPM"), access: 'campaign.cpm_bid'}
		,{value: 1, label: LANG("CPA优化"), access: 'campaign.cpa_opt'}
		,{value: 2, label: LANG("CPC优化"), access: 'campaign.cpc_opt'}
		,{value: 3, label: LANG("固定CPC"), access: 'campaign.cpc_fix'}
		,{value: 4, label: LANG("固定CPM"), access: 'campaign.cpm_fix'}
	];

	var CHARGE_TEXT = {
		1: LANG('优化CPA')
		,2: LANG('优化CPC')
		,3: LANG('结算CPC')
		,4: LANG('结算CPM')
	};

	// raido值定义
	var RAIDO_VALUE_DEFINE = pubjs.config('RAIDO_VALUE_DEFINE');
	var rvd = RAIDO_VALUE_DEFINE;

	// 修改出价
	var Price = view.container.extend({
		init: function(config) {
			// 权限判断
			for(var i = CHARGE_TYPE_OPTS.length -1; i >=0; i--) {
				var item = CHARGE_TYPE_OPTS[i];
				if(item.access && !pubjs.checkRight(item.access))
				{
					CHARGE_TYPE_OPTS.splice(i, 1);
				}
			}

			config = pubjs.conf(config, {
				view_model: {
					// 出价方式候选项
					'_ChargeTypeOpts': CHARGE_TYPE_OPTS
					// 出价方式
					,'ChargeType': CHARGE_TYPE_OPTS.length ? CHARGE_TYPE_OPTS[0].value : -1
					,'ChargeText': CHARGE_TEXT[1] || ''
					// 最高出价
					,'TopPrice': ''
					// 优化单价和结算
					,'TargetCpa': ''
				}
				,tplFile: 'tpl/campaign/batchEdit/price.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			self.vm.watch('ChargeType', function(v) {
				var vm = self.vm.$;
				if(+v)
				{
					vm.ChargeText = CHARGE_TEXT[v];
				}
			});
		}
		,reset: function() {
			this.vm.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			// 出价方式
			data.Way = this.vm.getItem('ChargeType');
			// 最高出价
			data.TopCpm = this.vm.getItem('TopPrice') || 0;
			// 优化单价
			data.Price = this.vm.getItem('TargetCpa') || 0;
			return data;
		},
		validate:function(data){
			if (+data.Way === -1) {
				pubjs.alert(LANG('没有权限'));
				return false;
			}
			//竞价CPM，校验最高出价
			if(+data.Way === 0 ){
				if( !util.isNumber(data.TopCpm) || data.TopCpm <= 0){
					pubjs.alert('竞价CPM下，最高出价请输入大于0的数字');
					return false;
				}
			} else if(!util.isNumber(data.Price) || data.Price <= 0){
				pubjs.alert("CPA和CPC," + CHARGE_TEXT[+data.Way] +"请输入大于0的数字");
				return false;
			}

			return true;
		}
	});
	exports.price = Price;

	// 修改预算
	var Budget = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
					// 总预算
					'TotalBudget': ''
					// 每日预算
					,'Budget': ''
				}
				,tplFile: 'tpl/campaign/batchEdit/budget.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.buildFromTemplate();
		}
		,reset: function() {
			this.$.totalBudget.setValue();
			this.$.budget.setValue();
			return this;
		}
		,getValue: function() {
			var data = {};
			// 总预算
			data.TotalBudget = +this.$.totalBudget.getValue() || 0;
			// 每日预算
			data.Budget = +this.$.budget.getValue() || 0;
			return data;
		}
	});
	exports.budget = Budget;

	// 投放速度
	var BidSpeed = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
					// 投放速度
					'GovernorStatus': 0
				}
				,tplFile: 'tpl/campaign/batchEdit/bidSpeed.tpl'
			});
			this.Super('init', arguments);
		}
		,reset: function() {
			this.vm.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			// 投放速度
			data.GovernorStatus = this.vm.getItem('GovernorStatus');
			return data;
		}
	});
	exports.bidSpeed = BidSpeed;

	// 频次控制
	var Frequency = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
					// 频次控制radio
					'_frequencyRadio': rvd.ALL
				}
				,tplFile: 'tpl/campaign/batchEdit/frequency.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.buildFromTemplate();
		}
		,afterBuildTemplate: function()
		{
			// 如果有数据为赋值，则异步创建完后再将数据setData
			if (this.$afterCreateData)
			{
				this.setValue(this.$afterCreateData);
				this.$afterCreateData = null;
			}
		}
		,reset: function() {
			this.vm.reset();
			this.$.frequency.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			// 频次控制
			if (this.vm.getItem('_frequencyRadio') != rvd.ALL) {
				data.FrequencyFilters = this.$.frequency.getData();
			}
			return data;
		}
		,setValue: function(data) {
			if (data)
			{
				// 如果模块已经创建，则直接setData
				if (this.$ && this.$.frequency)
				{
					if (data.FrequencyFilters && data.FrequencyFilters.length)
					{
						this.$.frequency.setData(data.FrequencyFilters);
						this.vm.$._frequencyRadio = rvd.NOT_ALL;
					}
				}
				// 模块还没创建，先保留数据，异步创建完后再将数据setData
				else
				{
					this.$afterCreateData = data;
				}
			}
			return this;
		}
	});
	exports.frequency = Frequency;

	// 人群选择
	var Character = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
					// 重定向radio
					'_characterRadio': rvd.ALL
				}
				,tplFile: 'tpl/campaign/batchEdit/character.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var c = this.getConfig();
			this.buildFromTemplate({
				// 重定向
				character: {
					'module_name': 'pdmp',
					'layout': {
						'module': 'campaign/modules/character.newPDMP',
						'url': 'PDMP/characters',
						'param': {
							'Type': c.channelType,
							'runstatus': 1
						}
					}
				}
			});
		}
		,afterBuildTemplate: function() {
			// 通知监听自身可见的模块可以开始加载数据了
			this.cast('startLoadData');
			// 监听radio变化，适应窗口位置
			this.vm.watch('_characterRadio', this.watchRadioChange);
		}
		,watchRadioChange: function() {
			this.fire('sizeChange');
		}
		,reset: function() {
			this.vm.reset();
			if(this.get('character')){
				this.get('character').destroy();
			}

			return this;
		}
		,getValue: function() {
			var data = {};
			// 重定向
			if (this.vm.getItem('_characterRadio') != rvd.ALL)
			{
				data.Character = this.$.character.getValue();
			}
			return data;
		},
		reload: function(channelType){
			var self = this;
			self.setConfig('channelType',channelType);

			// 重构
			self.createAsync('character', 'modules/loadOnVisible.base', {
				'module_name': 'pdmp',
				'layout': {
					'module': 'campaign/modules/character.newPDMP',
					'url': 'PDMP/characters',
					'param': {
						'Type': channelType,
						'runstatus': 1
					}
				},
				'target': self.getDOM().find('.characterCon')
			}, function(mod){
				if(mod && mod.get('pdmp')){
					mod.get('pdmp').load();
				}
			});
			return self;
		},
		show: function(channelType){
			var self = this;
			self.Super('show', arguments);
			// 更改活动类型的时候，重新构建和加载数据
			if(channelType){
				self.reload(channelType);
			}
			return self;
		}
	});
	exports.character = Character;

	// 投放日期
	var DDate = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				tplFile: 'tpl/campaign/batchEdit/date.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.buildFromTemplate({
				// 投放日期开始
				startTime: {
					value: util.date('Y-m-d')
				}
				// 投放结束日期
				,endTime: {
					min: util.date('Y-m-d')
				}
			});

		}
		,afterBuildTemplate: function()
		{
			// 如果有数据为赋值，则异步创建完后再将数据setData
			if (this.$afterCreateData)
			{
				this.setValue(this.$afterCreateData);
				this.$afterCreateData = null;
			}
		}
		,reset: function() {
			this.$.startTime.reset();
			this.$.endTime.reset();
			this.$afterCreateData = null;
			return this;
		}
		,getValue: function() {
			var data = {};
			data.StartTime = this.$.startTime.getData();
			data.EndTime = this.$.endTime.getData() || 0;
			return data;
		}
		,setValue: function(data) {
			if (data)
			{
				// 如果模块已经创建，则直接setData
				if (this.$ && this.$.startTime && this.$.endTime)
				{
					this.$.startTime.setData(data.StartTime);
					this.$.endTime.setData(data.EndTime);
				}
				// 模块还没创建，先保留数据，异步创建完后再将数据setData
				else
				{
					this.$afterCreateData = data;
				}
			}
			return this;
		}
	});
	exports.date = DDate;

	// 日程设置
	var Timeset = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
					// 日程设置radio
					'_TimeSetRadio': rvd.ALL
				}
				,tplFile: 'tpl/campaign/batchEdit/timeset.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.buildFromTemplate();
			this.vm.watch('_TimeSetRadio', this.watchRadioChange);
		}
		,watchRadioChange: function() {
			this.fire('sizeChange');
		}
		,reset: function() {
			this.vm.reset();
			this.$.timeset.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			// 日程设置
			data.TimeSet = {
				Type: this.vm.getItem('_TimeSetRadio') != rvd.ALL ? 2: 1,   // 1为全天投放，2为指定时间
				DayHour: this.$.timeset.getData()
			};
			return data;
		}
	});
	exports.timeset = Timeset;

	// 投放地区
	var Zone = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
					// 投放地区radio
					'_ZoneRadio': rvd.ALL
				}
				,tplFile: 'tpl/campaign/batchEdit/zone.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.getDOM().css('min-height', 400);
			this.buildFromTemplate();
			this.vm.watch('_ZoneRadio', this.watchRadioChange);
		}
		,watchRadioChange: function() {
			this.fire('sizeChange');
		}
		,reset: function() {
			this.vm.reset();
			this.$.zone.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			// 投放地区
			if (this.vm.getItem('_ZoneRadio') != rvd.ALL) {
				data.Zone = this.$.zone.getData();
			}
			return data;
		}
	});
	exports.zone = Zone;

	// 客户端
	var Client = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
					// 客户端radio
					'_clientRadio': rvd.ALL
				}
				,tplFile: 'tpl/campaign/batchEdit/client.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.buildFromTemplate();
			this.vm.watch('_clientRadio', this.watchRadioChange);
		}
		,watchRadioChange: function() {
			this.fire('sizeChange');
		}
		,reset: function() {
			this.vm.reset();
			this.$.client.reset()
			return this;
		}
		,getValue: function() {
			var data = {};
			// 客户端
			if (this.vm.getItem('_clientRadio') != rvd.ALL) {
				var clientData = this.$.client.getData() || {};
				data.OSType = clientData.os || null;       // 空数组为全选，null为不选
				data.BrowserType = clientData.bs || null;  // 空数组为全选，null为不选
			}
			return data;
		}
	});
	exports.client = Client;

	// 自有人群
	var BdxPeople = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
					// 自有人群radio
					'_bdxPeopleRadio': rvd.ALL
				}
				,tplFile: 'tpl/campaign/batchEdit/bdxPeople.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.buildFromTemplate({
				// 自有人群
				bdxPeople: {
					'layout': {
						'module': 'modules/inEx.base',
						'url': 'PDMP/bdxPeople'
					}
				}
			});
		}
		,afterBuildTemplate: function() {
			// 通知监听自身可见的模块可以开始加载数据了
			this.cast('startLoadData');
			this.vm.watch('_bdxPeopleRadio', this.watchRadioChange);
		}
		,watchRadioChange: function() {
			this.fire('sizeChange');
		}
		,reset: function() {
			this.vm.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			// 自有人群
			if (this.vm.getItem('_bdxPeopleRadio') != rvd.ALL) {
				data.BdxPeople = this.$.bdxPeople.getValue();
			}
			return data;
		}
	});
	exports.bdxPeople = BdxPeople;

	// 百度人群
	var BdPeople = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
					// 百度人群radio
					'_NPeopleRadio': rvd.ALL
				}
				,tplFile: 'tpl/campaign/batchEdit/bdPeople.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.buildFromTemplate({
				// 百度人群
				NPeople: {
					'layout': {
						'module': 'modules/inEx.base',
						'url': 'PDMP/bdPeople'
					}
				}
			});
		}
		,afterBuildTemplate: function() {
			// 通知监听自身可见的模块可以开始加载数据了
			this.cast('startLoadData');
			this.vm.watch('_NPeopleRadio', this.watchRadioChange);
		}
		,watchRadioChange: function() {
			this.fire('sizeChange');
		}
		,reset: function() {
			this.vm.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			// 百度人群
			if (this.vm.getItem('_NPeopleRadio') != rvd.ALL) {
				data.NPeople = this.$.NPeople.getValue();
			}
			return data;
		}
	});
	exports.bdPeople = BdPeople;

	// 秒针人群
	var MzPeople = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
					// 秒针人群radio
					'_MZPeopleRadio': rvd.ALL
				}
				,tplFile: 'tpl/campaign/batchEdit/mzPeople.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.buildFromTemplate({
				// 秒针人群
				MZPeople: {
					'layout': {
						'module': 'modules/inEx.base',
						'url': 'PDMP/mzPeople'
					}
				}
			});
		}
		,afterBuildTemplate: function() {
			// 通知监听自身可见的模块可以开始加载数据了
			this.cast('startLoadData');
			this.vm.watch('_MZPeopleRadio', this.watchRadioChange);
		}
		,watchRadioChange: function() {
			this.fire('sizeChange');
		}
		,reset: function() {
			this.vm.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			// 秒针人群
			if (this.vm.getItem('_MZPeopleRadio') != rvd.ALL) {
				data.MZPeople = this.$.MZPeople.getValue();
			}
			return data;
		}
	});
	exports.mzPeople = MzPeople;

	// 温度设置
	var Temperature = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
					// 温度radio
					'_temperatureType': rvd.ALL
				}
				,tplFile: 'tpl/campaign/batchEdit/temperature.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.buildFromTemplate();
			this.vm.watch('_temperatureType', this.watchRadioChange);
		}
		,watchRadioChange: function() {
			this.fire('sizeChange');
		}
		,reset: function() {
			this.vm.reset();
			this.$.temperature.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			var weather = data.Weather = {};
			// 温度
			if (this.vm.getItem('_temperatureType') != rvd.ALL) {
				var temperature = this.$.temperature.getData() || {};
				weather.TemperatureLevels = temperature.TemperatureLevels;
				weather.LowTemperature = temperature.LowTemperature;
				weather.HightTemperature = temperature.HightTemperature;
			}
			return data;
		}
	});
	exports.temperature = Temperature;

	// 湿度设置
	var Humidity = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
					// 湿度radio
					'_humidityType': rvd.ALL
				}
				,tplFile: 'tpl/campaign/batchEdit/humidity.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.buildFromTemplate({
				// 湿度
				humidity: {
					'items': dspUtil._convertMapToItems(pubjs.config('humidity'), true)
				}
			});
			this.vm.watch('_humidityType', this.watchRadioChange);
		}
		,watchRadioChange: function() {
			this.fire('sizeChange');
		}
		,reset: function() {
			this.vm.reset();
			this.$.humidity.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			var weather = data.Weather = {};
			// 湿度
			var humidity = weather.HumidityLevels = {};
			if (this.vm.getItem('_humidityType') !== rvd.ALL) {
				humidity.filterType = this.vm.getItem('_humidityType');
				humidity.result = this.$.humidity.getValue() || [];
			}
			return data;
		}
	});
	exports.humidity = Humidity;

	// 空气指数
	var Air = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
					// 空气指数radio
					'_AQIType': rvd.ALL
				}
				,tplFile: 'tpl/campaign/batchEdit/air.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.buildFromTemplate({
				// 空气指数
				AQI: {
					'items': dspUtil._convertMapToItems(pubjs.config('AQI'), true)
				}
			});
			this.vm.watch('_AQIType', this.watchRadioChange);
		}
		,watchRadioChange: function() {
			this.fire('sizeChange');
		}
		,reset: function() {
			this.vm.reset();
			this.$.AQI.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			var weather = data.Weather = {};
			// 空气指数
			weather.ApiLevels = {
				filterType: this.vm.getItem('_AQIType'),
				result: this.$.AQI.getValue() || []
			};
			return data;
		}
	});
	exports.air = Air;

	// 温差设置
	var TemperatureDiff = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
					// 温差radio
					'_temperatureDiff': rvd.ALL
				}
				,tplFile: 'tpl/campaign/batchEdit/temperatureDiff.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.buildFromTemplate();
			this.vm.watch('_temperatureDiff', this.watchRadioChange);
		}
		,watchRadioChange: function() {
			this.fire('sizeChange');
		}
		,reset: function() {
			this.vm.reset();
			this.$.temperatureDiff.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			// 温差
			if (this.vm.getItem('_temperatureDiff') != rvd.ALL) {
				data.TemperatureDiff = this.$.temperatureDiff.getData();
			}
			return data;
		}
	});
	exports.temperatureDiff = TemperatureDiff;

	// 百度指数
	var HotWord = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
					// 百度指数
					'_hotWordRadio': rvd.ALL
				}
				,tplFile: 'tpl/campaign/batchEdit/hotWord.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.buildFromTemplate();
			this.vm.watch('_hotWordRadio', this.watchRadioChange);
		}
		,watchRadioChange: function() {
			this.fire('sizeChange');
		}
		,reset: function() {
			this.vm.reset();
			this.$.hotWord.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			// 百度指数
			if (this.vm.getItem('_hotWordRadio') != rvd.ALL) {
				data.HotWord = this.$.hotWord.getData();
			}
			return data;
		}
	});
	exports.hotWord = HotWord;

	// 智能监控
	var SmartMonitor = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {
				}
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();

			$([
				'<div class="M-formConGroup">',
					'<label class="group-label">'+LANG('智能监控：')+'</label>',
					'<div class="group-content">',
						'<div class="" pub-name="campaignMonitor" pub-mod="campaign/modules/subs.campaignMonitor"/>',
					'</div>',
				'</div>'
			].join('')).appendTo(el);

			this.buildFromTemplate();

		}
		,reset: function() {
			this.vm.reset();
			this.$.campaignMonitor.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			var monitorData = this.$.campaignMonitor.getData();
			data.SmartMonitorAction = monitorData.SmartMonitorAction;
			data.AlarmIds = monitorData.AlarmIds;
			return data;
		}
	});
	exports.smartMonitor = SmartMonitor;

	// 溢价策略
	var NSpeculator = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model: {

				}
				,tplFile: 'tpl/campaign/batchEdit/nSpeculator.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.buildFromTemplate();
		}
		,onPolicysChange: function() {
			this.fire('sizeChange');
			return false
		}
		,reset: function() {
			this.vm.reset();
			this.$.nSpeculator.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			var nSpeculator = this.$.nSpeculator.getData();
			data.NSpeculator = nSpeculator;
			return data;
		}
	});
	exports.nSpeculator = NSpeculator;

	// 终端类型
	var TerminalType = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				view_model:{
					// 终端类型
					'TerminalType': 0
				}
				,tplFile: 'tpl/campaign/batchEdit/terminalType.tpl'
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.buildFromTemplate();
		}
		,reset: function() {
			this.vm.reset();
			return this;
		}
		,getValue: function() {
			var data = {};
			// 终端类型
			data.TargetPage = this.vm.getItem('TerminalType');
			return data;
		}
	});
	exports.terminalType = TerminalType;

	// 视频定向
	var VOrientation = view.container.extend({
		init: function(config){
			config = pubjs.conf(config, {
				tplFile: 'tpl/campaign/batchEdit/vOrientation.tpl',
				view_model: {
					// 视频定向开关
					'_videoOrientation': rvd.ALL
				}
			});
			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var config = {
				videoDirect: {
					'reqMethod': 'websocket',
					'list': {
						'type':{
							'text': LANG('按条件'),
							'module': 'campaign/modules/videoDirect.type',
							'class': 'P-campaignEditBodyVideoDirect'
						},
						'word':{
							'text': LANG('搜索'),
							'module': 'campaign/modules/videoDirect.word',
							'class': 'P-campaignEditBodyVideoDirect'
						}
					},
					'css': {
						'width': 950
					}
				}
			};
			this.buildFromTemplate(config);
		},
		getData: function(){
			var cs = this.$;
			var vmGet = this.vm.getItem.bind(this.vm);
			var data = {};
			var videoDirectWord = cs.videoDirect.get('word');
			var videoDirectType = cs.videoDirect.get('type');
			data.VideoDirect = {};
			data.VideoDirect['CategoryIds'] = videoDirectType.getData();
			data.VideoDirect['WordIds'] = videoDirectWord.getValue();
			data.VideoDirect['Status'] = false;
			if (vmGet('_videoOrientation') != rvd.ALL) {
				data.VideoDirect['Status'] = true;
			}

			return data;
		},
		reset: function(){
			var self = this;
			self.vm.reset();
			self.$.videoDirect.reset();
			return this;
		}
	});
	exports.vOrientation = VOrientation;

	// 三方监测
	var aMonitorUrl = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				'vModel': {
					'_MonitorRadio': rvd.ALL,
					'monitorPlaceholder': LANG('请输入监控的第三方调用的 URL 地址，暂不支持互众和腾讯渠道，多个 URL 地址请用回车换行隔开'),
					'ImpressionMonitor': '',
					'ClickMonitor': '',
				}
			});
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			this.append(`
				<div class="M-formConGroup">
					<label class="group-label">${LANG("三方监测")}</label>
					<div class="group-content">
						<div class="M-formSectionItem">
							<label>
								<input type="radio" v-model="_MonitorRadio" value="-1">
								<span>${LANG("关闭")}</span>
							</label>
							<label>
								<input type="radio" v-model="_MonitorRadio" value="0">
								<span>${LANG("开启")}</span>
							</label>
						</div>
						<div v-show="_MonitorRadio!=-1" class="mt20">
							<div>
								<label class="valign-t">${LANG("展示监测： ")}</label>
								<textarea class="w500 h70" v-bind:placeholder="monitorPlaceholder" v-model="ImpressionMonitor"/>
							</div>
							<div class="mt15">
								<label class="valign-t">${LANG("点击监测： ")}</label>
								<textarea class="w500 h70" v-bind:placeholder="monitorPlaceholder" v-model="ClickMonitor"/>
							</div>
						</div>
					</div>
				</div>
		`);

			this.vm.mount();
			this.buildFromTemplate({});
		}
		,reset: function() {
			this.vm.reset();
			return this;
		}
		,getValue: function() {
			var self = this;
			var vm = self.vm.$;
			var ALL   = RAIDO_VALUE_DEFINE.ALL;
			// 三方监测
			if(vm._MonitorRadio != ALL) {
				var ImpressionMonitor = [];
				var ClickMonitor = [];
				var murl = vm.ImpressionMonitor.replace(/[\r\n]+/g, '\n').split('\n');
				util.each(murl, function(item){
					if(util.trim(item)){
						ImpressionMonitor.push(util.trim(item));
					}
				});

				var murl = vm.ClickMonitor.replace(/[\r\n]+/g, '\n').split('\n');
				util.each(murl, function(item){
					if(util.trim(item)){
						ClickMonitor.push(util.trim(item));
					}
				});

				return {
					ThirdMonitor: {
						Exposure: ImpressionMonitor,
						Click: ClickMonitor
					}
				};
			}

			return {};
		}
	});
	exports.terminalType = TerminalType;

	// 活动列表 —— 批量操作的部分编辑内容
	var Main = popwin.extend({
		init:function(config) {
			config = pubjs.conf(config, {
				'class': 'P-campaignBatchEdit',
				'title': LANG('批量编辑'),
				'param': null,
				'silence': true,
				// 'width': 960,
				'size': 'm',
				'style': {'bodyClass': 'pr uk-form'},
				'types': {
					/**
					 * 配置说明
					 * [type]: {
					 *    url: '',          该类型的请求url
					 *    module: '',       该类型对应的模块，可为模块类，也可为uri
					 *    config: '',       模块对应配置
					 *    getter: 'getData' 获取数据方法，默认会调用模块的getValue，当为String时调用对应的方法，当为function时, function的this指向当前模块, 第一个参数为类型子模块实例
					 * }
					 */
					// 修改出价
					price: {
						module: Price,
						url: 'campaign/setCharge'
					},
					// 修改预算
					budget: {
						module: 'plan/modules/limit.batchEdit',
						url: 'campaign/setBudget'
					},
					// 投放速度
					bidSpeed: {
						module: BidSpeed,
						url: 'campaign/setGovernor'
					},
					// 频次控制
					frequency: {
						module: Frequency,
						url: 'campaign/setFrequency'
					},
					// 人群选择
					character: {
						module: Character,
						url: 'campaign/setCharacter'
					},
					// 投放日期
					date: {
						module: DDate,
						url: 'campaign/setPeriod'
					},
					// 日程设置
					timeset: {
						module: Timeset,
						url: 'campaign/setTimeSet'
					},
					// 投放地区
					zone: {
						module: Zone,
						url: 'campaign/setZone'
					},
					// 客户端
					client: {
						module: Client,
						url: 'campaign/setClient'
					},
					// 自有人群
					bdxPeople: {
						module: BdxPeople,
						url: 'campaign/'
					},
					// 百度人群
					bdPeople: {
						module: BdPeople,
						url: 'campaign/'
					},
					// 秒针人群
					mzPeople: {
						module: MzPeople,
						url: 'campaign/'
					},
					// 温度设置
					temperature: {
						module: Temperature,
						url: 'campaign/'
					},
					// 湿度设置
					humidity: {
						module: Humidity,
						url: 'campaign/'
					},
					// 空气指数
					air: {
						module: Air,
						url: 'campaign/'
					},
					// 温差设置
					temperatureDiff: {
						module: TemperatureDiff,
						url: 'campaign/'
					},
					// 百度指数
					hotWord: {
						module: HotWord,
						url: 'campaign/'
					},
					// 终端类型
					terminalType: {
						module: TerminalType,
						url: 'campaign/setTargetPage'
					},
					// 视频定向
					vOrientation: {
						module: VOrientation,
						url: 'campaign/setVOrientation',
						config: {
							css: {
								'min-height': 400
							}
						},
						getter: 'getData'
					},
					// 溢价策略
					nSpeculator: {
						module: NSpeculator,
						url: 'campaign/setNSpeculator'
					},
					// 智能监控
					smartMonitor: {
						module: SmartMonitor,
						url: 'campaign/setMonitor'
					},
					// 活动名称关键词替换
					nameReplace: {
						module: 'whisky/popwin/nameReplace.base',
						url: 'campaign/nameReplace',
						getter: 'getData'
					},
					aMonitorUrl: {
						module: aMonitorUrl,
						url: 'campaign/setAMonitorUrl',
						getter: 'getValue'
					}
				}
			});

			this.$param = {};
			this.$childPrefix = 'TYPE_CHILD_';
			this.$types = config.get('types');
			this.Super('init', arguments);

		},
		afterBuild:function() {
			this.Super('afterBuild', arguments);
			this.buildFromTemplate();
			var con = this.getContainer();
			con.css('background', '#fff');
		},
		reset: function() {
			var self = this;
			var cs = self.$;
			self.Super('reset', arguments);
			self.hideLoading();
			self.$currentType = null;
			// 重置子模块
			util.each(self.$types, function(opts, type) {
				var name = self.$childPrefix + type;
				if (cs[name]) {
					cs[name].reset().hide();
				}
			});
			return self;
		},
		// 设置活动类型
		setChannelType: function(channel){
			// 活动类型，区分pc，移动，监测
			this.$channelType = channel || 0;
			return this;
		},
		// 设置类型
		setType: function(type) {
			var self = this;
			var types = self.$types;

			switch (type){
				case 'character':
				case 'timeset':
				case 'bdxPeople':
				case 'bdPeople':
				case 'mzPeople':
				case 'smartMonitor':
				case 'nSpeculator':
					self.setWidth(1000);
					break;
				case 'zone':
				case 'client':
				case 'vOrientation':
					self.setWidth(1200);
					break;
				default:
					self.setWidth(850);
			}

			var pre = self.$childPrefix;
			var name = pre + type;
			var opts = types[type || ''];
			var config = util.extend(opts.config, {target: this.getContainer(),channelType: self.$channelType});
			var afterCreate = function(mod) {
				self.hideLoading();
				opts.loading = false;
				self.update();
				mod.show();

				// 模块创建中，上层调用了setData的值，在模块创建完后，这值对应的值
				if (opts.afterCreateData && mod.setValue)
				{
					mod.setValue(opts.afterCreateData);
				}
			}

			if (opts) {
				self.$currentType = type;

				// 如果模块不存在
				if (!self.$[name]) {
					// 模块还没创建完毕，loading盖住
					if (opts.loading) {
						self.showLoading();
					// 异步创建模块，创建过程上锁，并用loading盖住
					} else if (util.isString(opts.module)) {
						opts.loading = true;
						self.showLoading();
						self.createAsync(name, opts.module, config, afterCreate);
					// 同步创建模块
					} else if (util.isClass(opts.module)){
						opts.loading = true;
						self.showLoading();
						afterCreate(self.create(name, opts.module, config));
					} else {
						pubjs.error("类型为:" + type + "的module属性配置错误");
					}
				} else {
					self.$[name].show(self.$channelType);
					self.update();
				}
			} else {
				pubjs.error("配置中找不到该类型:" + type);
			}

			return this;
		},
		setParam: function(ids) {
			this.$param = {
				ids: ids
			};
			return this;
		},
		setData: function(data)
		{
			if (data)
			{
				var self = this;
				var types = self.$types;
				var type = self.$currentType;
				var pre = self.$childPrefix;
				var name = pre + type;

				var opts = types[type];
				if (opts)
				{
					if (opts.loading)
					{
						opts.afterCreateData = data;
					}
					else if(self.$[name] && self.$[name].setValue)
					{
						self.$[name].setValue(data);
					}
				}
			}
			return this;
		},
		save: function() {
			var data;
			var self = this;
			var type = self.$currentType;
			var opts = self.$types[type];
			var name = self.$childPrefix + type;
			var mod = self.get(name);
			var getter = opts.getter;

			if (!getter) {
				data = mod.getValue();
			} else if (util.isString(getter)) {
				data = mod[getter]();
			} else if (util.isFunction(getter)) {
				data = getter.apply(self, mod, opts);
			}

			//有写校验函数则校验
			if(mod.validate){
				if(!mod.validate(data)){
					return false;
				}
			}


			if (data) {
				data = util.extend(data, self.$param);
				self.showLoading();
				pubjs.mc.send(opts.url, data, self.afterSave.bind(self));
			}
		},
		afterSave: function(err, data) {
			this.hideLoading();
			if (err) {
				return pubjs.alert(err.message || LANG('修改失败'));
			}

			this.hide();
			if((data && data.ids) && !data.ids.length)
			{
				pubjs.alert(LANG('修改失败'));
			}
			else
			{
				pubjs.alert(LANG('修改成功'))
			}

			this.fire('batchEditSuccess', {type: this.$currentType});
		},
		showLoading: function() {
			var con = this.getContainer();
			this.$isloading = true;

			if (!this.$loadingEl) {
				this.$loadingEl = $('<div class="M-tableListLoading bottom-right">').appendTo(con);
			}
			this.$loadingEl.show();
			return this;
		},
		hideLoading: function() {
			this.$isloading = false;
			if (this.$loadingEl) {
				this.$loadingEl.hide();
			}
		},
		onOk: function() {
			if (!this.$isloading) {
				this.save();
			}
			return false;
		}
	});

	exports.main = Main;

});